package com.huang.core.widget.recyclerview.decoration

import android.graphics.Color
import android.view.View
import androidx.annotation.IntRange
import com.huang.core.widget.recyclerview.decoration.base.Y_Divider
import com.huang.core.widget.recyclerview.decoration.base.Y_DividerBuilder
import com.huang.core.widget.recyclerview.decoration.base.Y_ItemDecoration


class GridDividerItemDecoration(
        @IntRange(from = 1, to = Int.MAX_VALUE.toLong()) private val columnCount: Int,
        private val size: Float = 0.5f,
        private val padding: Float = 0f,
        private val colorInt: Int = Color.parseColor("#dddddd")
) : Y_ItemDecoration() {

    override fun getDivider(itemPosition: Int, itemCount: Int, view: View): Y_Divider {
        val indexInLine = itemPosition % columnCount

        return if (columnCount == 1) {
            Y_DividerBuilder()
                    .setBottomSideLine(true, colorInt, size, padding, padding)
                    .create()
        } else if (indexInLine == 0) {
            Y_DividerBuilder()
                    .setBottomSideLine(true, colorInt, size, padding, padding)
                    .create()
        } else if (indexInLine == columnCount - 1) {
            Y_DividerBuilder()
                    .setBottomSideLine(true, colorInt, size, padding, padding)
                    .create()
        } else {
            Y_DividerBuilder()
                    .setLeftSideLine(true, colorInt, size / 2, padding, padding)
                    .setRightSideLine(true, colorInt, size / 2, padding, padding)
                    .setBottomSideLine(true, colorInt, size, padding, padding)
                    .create()
        }
    }
}